package alexattar.gdxtest.screens;

import static com.badlogic.gdx.scenes.scene2d.actions.Actions.delay;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeIn;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeOut;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence;

import alexattar.gdxtest.GdxTestGame;
import alexattar.gdxtest.services.MusicManager.TyrianMusic;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Scaling;

public class SplashScreen extends AbstractScreen {

	private Image splashImage;
	
	public SplashScreen( GdxTestGame game) {
		super(game);
	}

	@Override
	public void show() {
		super.show();
		game.getMusicManager().play(TyrianMusic.MENU);
		
		AtlasRegion splashRegion = getAtlas().findRegion("splash-screen/splash-image_l,l");
		Drawable splashDrawable = new TextureRegionDrawable(splashRegion);
		
		splashImage = new Image(splashDrawable, Scaling.stretch);
		splashImage.setFillParent(true);
		
		splashImage.getColor().a = 0f;
		splashImage.addAction(sequence(fadeIn(0.75f), delay(1.75f), fadeOut(0.75f), 
		new Action() {
			@Override
			public boolean act(float delta) {
				game.setScreen(new MenuScreen(game));
				return true;
			}
		}));
		stage.addActor(splashImage);
	}

}
